package com.yld.scott.ch02;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

import com.google.gson.Gson;
import com.yld.scott.ch01.StudentEntity;

public class ArrayListTest {
	
	
	
	
	@Test
	public void list() throws Exception {
		
		List<String> studentList = new ArrayList<String>();
		
		StudentEntity cwh=  new StudentEntity("陈文辉",22);
		StudentEntity lp =  new StudentEntity("陈文辉",22);
		
		
		studentList.add(cwh.getStudentName());
		studentList.add(lp.getStudentName());
		
		
		System.out.println(studentList.size());
		
		
	}
	
	
	@Test
	public void hashmap() throws Exception {
		
		Map<String,StudentEntity> map = new HashMap<String,StudentEntity>();
		
		StudentEntity cwh=  new StudentEntity("陈文辉",22);
		StudentEntity lp =  new StudentEntity("李澎",20);
		
		
		map.put(cwh.getStudentName(), cwh);
		map.put(lp.getStudentName(), lp);
		
		
		System.out.println(map.size());
		
		
		Set<String> names = map.keySet();
		
		
		Iterator<String> it = names.iterator();
		
		while(it.hasNext()){
			
			String name = it.next();
			System.out.println("key="+name);
			
			StudentEntity value = map.get(name);
			System.out.println("value="+new Gson().toJson(value));
		}
		
		
		
	}
	
	
	@Test
	public void set() throws Exception {
		
		Set<String> studentList = new HashSet<String>();
		
		StudentEntity cwh=  new StudentEntity("陈文辉",22);
		StudentEntity lp =  new StudentEntity("李澎",22);
		
		
		studentList.add(cwh.getStudentName());
		studentList.add(lp.getStudentName());
		
		
		System.out.println(studentList.size());
		
		
	}
	
	
	@Test
	public void set02() throws Exception {
		
		Set<String> studentList = new HashSet<String>();
		
		String cwh = "陈文辉";
//		String lp  = "李澎";
		String lp  = "陈文辉";
		
		System.out.println(cwh.equals(lp));
		
		
		studentList.add(cwh);
		studentList.add(lp);
		
		
		System.out.println(studentList.size());
		
		
	}

}
